using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;
using Water.DA;
using Water.Util;
using System.Collections;
using Water.Web.Controls.Transform;
using Water.Web.Controls.TypeConverter;

namespace Water.Web.Controls
{
    [ToolboxData("<{0}:SqlDataSource runat=server></{0}:SqlDataSource>")]
    public class SqlDataSource:System.Web.UI.WebControls.SqlDataSource
    {
        /*private string dataField;

        [Category("Data"), DefaultValue(""), Description("...")]
        public string DataField
        {
            get { return dataField; }
            set { dataField = value; }
        }
        private string headerField;

        [Category("Data"), DefaultValue(""), Description("...")]
        public string HeaderField
        {
            get { return headerField; }
            set { headerField = value; }
        }
        private string xField;

        [Category("Data"), DefaultValue(""), Description("...")]
        public string XField
        {
            get { return xField; }
            set { xField = value; }
        }
        private string yField;

        [Category("Data"), DefaultValue(""), Description("...")]
        public string YField
        {
            get { return yField; }
            set { yField = value; }
        }
        private string dataFieldSeparator = ",";

        [Category("Data"), DefaultValue(","), Description("...")]
        public string DataFieldSeparator
        {
            get { return dataFieldSeparator; }
            set { dataFieldSeparator = value; }
        }

        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (String.IsNullOrEmpty(base.ConnectionString))
            {
                ConnectionStringSettings css = Water.Util.Configuration.GetConnectionString();
                base.ConnectionString = css.ConnectionString;
                base.ProviderName = css.ProviderName;
            }
        }

        protected override SqlDataSourceView CreateDataSourceView(string viewName)
        {
            if (string.IsNullOrEmpty(DataField) && string.IsNullOrEmpty(HeaderField) && string.IsNullOrEmpty(XField) && string.IsNullOrEmpty(YField))
            {
                //return base.CreateDataSourceView(viewName);
                return new SqlDataSourceViewPager(this,viewName, this.Context);
            }
            else
            {
                if (string.IsNullOrEmpty(DataField)) throw new ArgumentNullException("DataField");
                else if (string.IsNullOrEmpty(HeaderField)) throw new ArgumentNullException("HeaderField");
                else if (string.IsNullOrEmpty(XField)) throw new ArgumentNullException("XField");
                else if (string.IsNullOrEmpty(YField)) throw new ArgumentNullException("YField");
                else
                {
                    SqlDataSourceViewTransform dataSourceViewTransform = new SqlDataSourceViewTransform(this, viewName, this.Context);
                    dataSourceViewTransform.DataField = this.DataField;
                    dataSourceViewTransform.HeaderField = this.HeaderField;
                    dataSourceViewTransform.XField = this.XField.Split(new char[] { ',' });
                    dataSourceViewTransform.YField = this.YField.Split(new char[] { ',' });
                    dataSourceViewTransform.DataFieldSeparator = this.DataFieldSeparator;
                    return dataSourceViewTransform;
                }
            }
        }*/

        /*
        private string queryControlID;

        [Browsable(true), TypeConverter(typeof(ContainerIDConver)), Category("Behavior"), GlobalizeDescription("QueryControlID")]
        public string QueryControlID
        {
            get { return queryControlID; }
            set { queryControlID = value; }
        }
        */
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            if (String.IsNullOrEmpty(base.ConnectionString))
            {
                ConnectionStringSettings css = Water.Util.Configuration.GetConnectionString();
                base.ConnectionString = css.ConnectionString;
                base.ProviderName = css.ProviderName;
            }
        }
        /*
        protected override DataSourceView GetView(string viewName)
        {
            DataSourceView _dsv = base.GetView(viewName);
            ((SqlDataSourceView)_dsv).Selecting += new SqlDataSourceSelectingEventHandler(SqlDataSource_Selecting);
            return _dsv;
        }

        void SqlDataSource_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
        {
            throw new NotImplementedException();
        }
        */
    }
}
